﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NAccounting.Controllers
{
    public class AccountPlanController : Controller
    {
        private NAccountEntities db = new NAccountEntities();

        //
        // GET: /AccountPlan/

        public ActionResult Index()
        {
            return View();
        }


        public JsonResult GetAccountPlanByText(string term)
        {
            //System.Threading.Thread.Sleep(5000);

            var query = db.AccountPlans
                          .Where(x => x.FormattedAccount.Contains(term) || x.Name.Contains(term))
                          .Take(10)
                          .ToArray();

            var result = query.Select(x => new { id = x.Id, value = x.ToString()});
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}
